package com.example.demo1109.demo3;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class Broker implements MethodInterceptor {
    private Object actor;

    public Broker(Object actor) {
        this.actor = actor;
    }
    public Object getInstance(){
        Enhancer enhancer=new Enhancer();
        enhancer.setSuperclass(actor.getClass());
        enhancer.setCallback(this);
        return enhancer.create();
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        negotiate();
        extend();
        Object invoke = method.invoke(actor, objects);
        acknowledge();
        return invoke;
    }
    public void negotiate(){
        System.out.println("洽谈出场费");
    }
    public void extend(){
        System.out.println("向观众问好");
    }
    public void acknowledge(){
        System.out.println("向观众答谢");
    }
}
